package com.share.service.es;

import com.share.domain.learn.User;
import com.share.es.UserESRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.query.IndexQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author caifan
 * 2018/6/26
 */
@Service
public class ESService extends ESBaseService {
    @Autowired
    UserESRepository userESRepository;

    public List<User> searchUser() {
        List<User> userList = (List<User>)userESRepository.findAll();
        return userList;
    }

    /*public List<User> getUsersByTerms() {
        QueryBuilder queryBuilder = new TermsQueryBuilder("username.keyword", new String[]{"刘二", "刘二12", "刘二7"});
        SearchQuery searchQuery = new NativeSearchQuery(queryBuilder);
        searchQuery.setPageable(PageRequest.of(0, 30));
        List<User> users = elasticsearchTemplate.queryForList(searchQuery, User.class);
        return users;
    }*/
}
